package com.foreveross.vo;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.foreveross.vo.common.AffiliatedBaseVo;

/**
 * Tenement entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "tenement", catalog = "hrtenement")
public class Tenement extends AffiliatedBaseVo implements java.io.Serializable {

	// Fields

	private String id;
	private String name;
	private String address;
	private HrHouses houseId;
	private String house_id;
    private String house_name;
	private String appId;
	private String appSecret;
	private String mchId;
	private String apiKey;
	private String certUrl;
	
	private List<TenementDepartment> tenementDepartmentList;

	// Constructors

	/** default constructor */
	public Tenement() {
	}

	/** minimal constructor */
	public Tenement(String id) {
		this.id = id;
	}

	/** full constructor */
	public Tenement(String id, String name, String address,
			HrHouses house_id,String house_name) {
		this.id = id;
		this.name = name;
		this.address = address;
		this.houseId = house_id;
		this.house_name = house_name;
	}

	@Id
	@GenericGenerator(name="idGenerator", strategy="uuid")
	@GeneratedValue(generator="idGenerator") 
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "address")
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

 
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "house_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public HrHouses getHouseId() {
		return this.houseId;
	}

	public void setHouseId(HrHouses houseId) {
		this.houseId = houseId;
	}

	
	@Transient
	public String getHouse_id() {
		if(houseId!=null)
			return this.houseId.getId();
		return house_id;
	}

	public void setHouse_id(String house_id) {
		this.house_id = house_id;
	}

	@Transient
	public String getHouse_name() {
		return house_name;
	}

	public void setHouse_name(String house_name) {
		this.house_name = house_name;
	}
	
	@Column(name = "app_id")
	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}
	
	@Column(name = "app_secret")
	public String getAppSecret() {
		return appSecret;
	}

	public void setAppSecret(String appSecret) {
		this.appSecret = appSecret;
	}

	@Column(name = "mch_id")
	public String getMchId() {
		return mchId;
	}

	public void setMchId(String mchId) {
		this.mchId = mchId;
	}
	@Column(name = "api_key")
	public String getApiKey() {
		return apiKey;
	}

	public void setApiKey(String apiKey) {
		this.apiKey = apiKey;
	}
	
	@Column(name = "cert_url")
	public String getCertUrl() {
		return certUrl;
	}

	public void setCertUrl(String certUrl) {
		this.certUrl = certUrl;
	}
	
	@OneToMany(fetch = FetchType.LAZY, cascade={CascadeType.ALL})
	@JoinColumn(name="tenement_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public List<TenementDepartment> getTenementDepartmentList() {
		return tenementDepartmentList;
	}

	public void setTenementDepartmentList(
			List<TenementDepartment> tenementDepartmentList) {
		this.tenementDepartmentList = tenementDepartmentList;
	}
}